package cn.lll.vuehouse.controller;

import cn.lll.vuehouse.common.ResponseResult;
import cn.lll.vuehouse.common.ResponseStatus;
import cn.lll.vuehouse.dto.DeptDto;
import cn.lll.vuehouse.entity.Dept;
import cn.lll.vuehouse.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("dept")
public class DeptController {

    @Autowired
    DeptService deptService;

    @GetMapping("getDeptsList")
    public ResponseResult getDeptsList(){
        return deptService.getDeptsList();
    }

    @PostMapping("getCurrentPageDeptInfo")
    public ResponseResult getCurrentPageDeptInfo(@RequestBody DeptDto deptDto){
        return deptService.getCurrentPageDeptInfo(deptDto);
    }

    // 删除部门通过ID
    @DeleteMapping("deleteByIdDept")
    public ResponseResult deleteByIdDept(Integer id){
        return deptService.deleteByIdDept(id);
    }

    // 获取编辑部门表单回显数据
    @GetMapping("getFullDeptInfo")
    public ResponseResult getFullDeptInfo(Integer id){
        Dept dept = deptService.getById(id);
        ResponseResult responseResult = new ResponseResult();
        responseResult.success(ResponseStatus.SUCCESS, dept);
        return responseResult;
    }

    // 新增或更新部门共用接口
    @PostMapping("addAndUpdateDept")
    public ResponseResult addAndUpdateDept(@RequestBody Dept dept){
        return deptService.addAndUpdateDept(dept);
    }

    // 改变部门状态
    @PutMapping("changeAvailable")
    public ResponseResult changeAvailable(@RequestBody Dept dept){
        deptService.updateById(dept);
        ResponseResult responseResult = new ResponseResult();
        responseResult.success(ResponseStatus.SUCCESS);
        return responseResult;
    }
}
